/**
 * 
 */
package sourceFiles;

import java.util.HashMap;

import Exceptions.InvalidAgeParam;
import Exceptions.InvalidCapacity;
import Exceptions.InvalidHeightParam;
import Exceptions.InvalidRideId;
import Exceptions.InvalidRideName;
import Exceptions.XMLRidesParserException;
import Exceptions.CentralComputerExceptions.RideIDDoesntExist;

/**
 * @author LASO-Team
 *
 */
public class SupervisorStation implements ISupervisorStation {

	private ICentralComputer centralComputer;

	/*--------------------------------------------------------------------------*/

	/**
	 * a test for the parameters enterd, throws (as described) if any errors
	 * occur. on success does nothing
	 * 
	 * @param maxCapacity
	 *            the maximal amount of users in the ride
	 * @param minAge
	 *            the minimal age of the users of the ride
	 * @param minHeight
	 *            the minimal height of the users in the ride
	 * @throws InvalidCapacity
	 *             if the capacity entered is less than 1.
	 * @throws InvalidAge
	 *             if the age entered is less than 1.
	 * @throws InvalidHeight
	 *             if the height entered is less than 1.
	 */
	private void checkRideParams(Integer maxCapacity, Integer minAge,
			Integer minHeight) throws InvalidCapacity, InvalidAgeParam,
			InvalidHeightParam {
		if (maxCapacity < 1) {
			throw new InvalidCapacity();
		} else if (minAge < 1) {
			throw new InvalidAgeParam();
		} else if (minHeight < 1) {
			throw new InvalidHeightParam();
		}
	}

	/*--------------------------------------------------------------------------*/

	/**
	 * a simple constructor for the supervisor station
	 * 
	 * @param centralComputer
	 *            the server that the station logs to.
	 */
	public SupervisorStation(ICentralComputer centralComputer) {
		this.centralComputer = centralComputer;
	}

	@Override
	public Integer createNewRide(String rideName, Boolean isExtreme,
			Integer maxCapacity, Integer minAge, Integer minHeight)
			throws InvalidRideName, InvalidCapacity, InvalidAgeParam,
			InvalidHeightParam, XMLRidesParserException {
		if (rideName == null) {
			throw new InvalidRideName();
		}
		checkRideParams(maxCapacity, minAge, minHeight);
		return centralComputer.createRide(rideName, isExtreme, maxCapacity,
				minAge, minHeight);
	}

	@Override
	public void editRideParams(Integer rideID, Integer maxCapacity,
			Integer minAge, Integer minHeight) throws InvalidRideId,
			InvalidCapacity, InvalidAgeParam, InvalidHeightParam,
			RideIDDoesntExist, XMLRidesParserException {
		if (rideID < 1) {
			throw new InvalidRideId();
		}
		checkRideParams(maxCapacity, minAge, minHeight);
		centralComputer.updateRide(rideID, maxCapacity, minAge, minHeight);
	}

	@Override
	public HashMap<Integer, Integer> getTicketsAmount() {
		return centralComputer.getTicketsSold();
	}

}
